
    var video = document.getElementById('video'),
		canvas = document.getElementById('canvas'),
		snap = document.getElementById('tack'),
		img = document.getElementById('img'),
		vendorUrl = window.URL || window.webkitURL;
		
	//媒体对象
	function init(val) {
        navigator.getMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
        var mode = val ? "user" : "environment" 
        console.log(mode)
        navigator.getMedia({
            video: { 
                // width: { min: 1024, ideal: 1280, max: 1920 },
                // height: { min: 776, ideal: 720, max: 1080 },
                // frameRate: { ideal: 10, max: 15 },
                facingMode: mode// (front? "" : "environment")
            }
        }, function(strem){
            console.log(strem);
            // video.src = vendorUrl.createObjectURL(strem);
            video.srcObject = strem;
            video.play();
        }, function(error) {
            //error.code
            console.log(error);
        });
    }
    init()
    var a= true;
	snap.addEventListener('click', function(){
        // a = !a
        // if (a) {
        //     init(a)
        // } else {
        //     init(a)
        // }
        
		//绘制canvas图形
		canvas.getContext('2d').drawImage(video, 0, 0, 400, 300);
		
		//把canvas图像转为img图片
		url = canvas.toDataURL("image/png");
        console.log(url)
		
	})